<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
</body>

</html>
<script>
    //路由器需要注册的全部异步路由
    let asyncRoue = [
        {
            name: 'Product',
            children: [{ name: 'Trademark' }, { name: 'Attr' }, { name: 'Spu' }, { name: 'Sku' }]
        }
        ,
        {
            name: 'Test',
            children: [{ name: 'Add' }, { name: 'Delete' }, { name: 'Update' }, { name: 'Search' }]
        }
    ];
    //讲师账号登录
    let routes = ["Product", "Spu", "Sku", "Test", "Delete"];
    //过滤异步路由
    function filterAsnycRoute (asyncRoue, routes)
    {
        let result = asyncRoue.filter(item =>
        {
            if (routes.includes(item.name)) {
                if (item.children && item.children.length > 0) {
                    item.children = filterAsnycRoute(item.children, routes);
                }
                return true;
            }
        });
        return result;
    }
    let jieguo = filterAsnycRoute(asyncRoue, routes);
    console.log(jieguo);


</script>